﻿#pragma once

#include <list>

#ifdef _WIN32_WINNT
#undef _WIN32_WINNT
#endif

#define _WIN32_WINNT 0x0400

#include "windows.h"

typedef VOID (CALLBACK *FiberProc)(PVOID lpParameter);

class FiberMgr
{
public:
	typedef LPVOID FiberID;
	typedef std::list<FiberID> Fibers;
private:
	FiberMgr(void);
	virtual ~FiberMgr(void);

public:
	static FiberMgr& instance();
	void onFrame();
	void loop(int interval = 1000);

	FiberID createFiber(FiberProc proc, LPVOID args);
	void deleteFiber(FiberID fid);
	void switchToMainFiber();
	void endFiber(FiberID fid);
	void switchToFiber(FiberID fid);

private:

	FiberID main_fiber_;
	Fibers fibers_;
	Fibers die_fibers_;
};
